const { contextBridge, ipcRenderer } = require('electron');

// 暴露安全的API给渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
  // ping功能
  pingTarget: (ip) => ipcRenderer.invoke('ping-target', ip),
  
  // 获取精确时间
  getPreciseTime: () => ipcRenderer.invoke('get-precise-time'),
  
  // 窗口控制
  minimizeWindow: () => ipcRenderer.send('minimize-window'),
  closeWindow: () => ipcRenderer.send('close-window'),
  toggleAlwaysOnTop: () => ipcRenderer.send('toggle-always-on-top'),
  
  // 设置窗口透明度
  setOpacity: (opacity) => ipcRenderer.send('set-opacity', opacity),
  
  // 监听事件
  onPingResult: (callback) => ipcRenderer.on('ping-result', callback),
  removePingListener: () => ipcRenderer.removeAllListeners('ping-result')
}); 